package com.ymatou.iapi.couponmanage.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponmanage.parameter.BatchInfo;
import com.ymatou.iapi.couponmanage.parameter.CreateBagBean;
import com.ymatou.iapi.couponmanage.parameter.CreateBean;
import com.ymatou.iapi.couponmanage.parameter.CreateCouponBean;
import com.ymatou.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.couponmanage.parameter.createTaskByUserIdBean;
import com.ymatou.iapi.couponmanage.service.CreateBagCall;
import com.ymatou.iapi.couponmanage.service.CreateCall;
import com.ymatou.iapi.couponmanage.service.CreateCouponCall;
import com.ymatou.iapi.couponmanage.service.SellerCreateBatchCall;
import com.ymatou.iapi.couponmanage.service.createTaskByUserIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.model.couponsendsubtask;
import com.ymttest.database.model.couponsendtask;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.database.sqlwapper.couponsendsubtaskWapper;
import com.ymttest.database.sqlwapper.couponsendtaskWapper;
/**
*根据用户Id列表创建发券任务
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_createTaskByUserId{
	private static createTaskByUserIdBean createtaskbyuseridBean;
	private static createTaskByUserIdCall createtaskbyuseridCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据用户Id列表创建发券任务");
	}

	@Before
	public void caseUp() {
		createtaskbyuseridBean=new createTaskByUserIdBean();
		createtaskbyuseridCall=new createTaskByUserIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createtaskbyuseridCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_createTaskByUserId_001() {
		Logger.start(true,"根据用户Id列表创建发券任务-平台券");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(1);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();
			//createtaskbyuseridCall.callService();
		//	Thread.sleep(5000);
			verifyReturn(1);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_createTaskByUserId_031() {
		Logger.start(true,"根据用户Id列表创建发券任务-商家券");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean createCouponBean = couponCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall = couponCallService.SellerCreateBatch(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();
		//	createtaskbyuseridCall.callService();

			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("不属于平台批次"), "验证errorMessage");
			Logger.verifyEquals(2, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("不属于平台批次"), "验证message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_createTaskByUserId_002() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证userIds-集合总数小于100");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			userIds.add(22);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();			
			verifyReturn(1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_023() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证userIds-userIds总数大于优惠券");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setCouponNum(1);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			userIds.add(22);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();
			
			Logger.verifyEquals(0, createtaskbyuseridCall.getTaskId(), "验证返回的TaskId=0");
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("优惠券数量不足"), "验证errorMessage");
			Logger.verifyEquals(2, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("优惠券数量不足"), "验证message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_003() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证userIds-集合总数大于100");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setCouponNum(200);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			for(int i=1;i<200;i++)
			{
			  userIds.add(i);
			}
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			verifyReturn(1);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_028() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证userIds-集合总数等于1000");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setCouponNum(2000);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			for(int i=1;i<=1000;i++)
			{
			  userIds.add(i);
			}
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			verifyReturn(1);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_029() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证userIds-集合总数大于1000");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setCouponNum(2000);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			for(int i=1;i<1500;i++)
			{
			  userIds.add(i);
			}
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("userIds:发放用户数必须在1-1000之间"), "验证errorMessage");
			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("userIds:发放用户数必须在1-1000之间"), "验证message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_createTaskByUserId_004() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证userIds-集合总数等于100");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setCouponNum(200);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			for(int i=1;i<100;i++)
			{
			  userIds.add(i);
			}
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		
			verifyReturn(1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	@Ignore
	public void Ts_createTaskByUserId_005() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证userIds-包含不存在的用户Id");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		
			verifyReturn(1);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_createTaskByUserId_006() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchType=1(普通批次)");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		
			verifyReturn(1);			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_createTaskByUserId_007() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchType=2(套券)");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);
			createtaskbyuseridBean.setBatchCode(createBagCall.getbagCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		
			verifyReturn(4);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_createTaskByUserId_008() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchType不存在");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(3);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		
			
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("batchType:批次类型必须是1或2，1：普通批次，2：套券"), "验证errorMessage");
			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("batchType:批次类型必须是1或2，1：普通批次，2：套券"), "验证message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_009() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-普通批次batchCode不存在");
		try {
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode("batchCode");
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();				
			
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("批次不存在"), "验证errorMessage");
			Logger.verifyEquals(2, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("批次不存在"), "验证message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_010() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-普通批次batchCode为空");
		try {
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode("");
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();				
			
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("必须传入批次编号"), "验证errorMessage");
			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("必须传入批次编号"), "验证message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_011() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-套券批次batchCode不存在");
		try {
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode("batchCode");
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();				
			
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("套券批次不存在"), "验证errorMessage");
			Logger.verifyEquals(2, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("套券批次不存在"), "验证message");					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_012() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-套券批次batchCode为空");
		try {
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode("");
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();				
			
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("必须传入批次编号"), "验证errorMessage");
			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("必须传入批次编号"), "验证message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_013() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-套券批次中含有无效子任务");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
			BatchInfo info=new BatchInfo();
			info.setCouponName("自动化创建套券优惠券名称-子套券");
			info.setCouponDes("自动化创建套券优惠券描述-子套券");
			info.setApplyMemo("自动化创建申请理由-子套券");
			info.setOrderMinAmount(new BigDecimal(2));
			info.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds = new ArrayList<String>();
			info.setProductIds(productIds);
			List<Integer> SellerIds = new ArrayList<Integer>();
			info.setSellerIds(SellerIds);
			List<Integer> ActivityIds = new ArrayList<Integer>();
			info.setActivityIds(ActivityIds);
			List<Integer> Brands = new ArrayList<Integer>();
			info.setBrands(Brands);
			List<Integer> Countrys = new ArrayList<Integer>();
			info.setCountrys(Countrys);
			List<Integer> Categories = new ArrayList<Integer>();
			info.setCategories(Categories);
			info.setLimitPspProduct(false);
			BatchInfos.add(info);
			
			BatchInfo info1=new BatchInfo();
			info1.setCouponName("自动化创建套券优惠券名称-子套券1");
			info1.setCouponDes("自动化创建套券优惠券描述-子套券1");
			info1.setApplyMemo("自动化创建申请理由-子套券1");
			info1.setOrderMinAmount(new BigDecimal(2));
			info1.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds1 = new ArrayList<String>();
			info1.setProductIds(productIds1);
			List<Integer> SellerIds1 = new ArrayList<Integer>();
			info1.setSellerIds(SellerIds1);
			List<Integer> ActivityIds1 = new ArrayList<Integer>();
			info1.setActivityIds(ActivityIds1);
			List<Integer> Brands1 = new ArrayList<Integer>();
			info1.setBrands(Brands1);
			List<Integer> Countrys1 = new ArrayList<Integer>();
			info1.setCountrys(Countrys1);
			List<Integer> Categories1 = new ArrayList<Integer>();
			info1.setCategories(Categories1);
			info1.setLimitPspProduct(false);
			BatchInfos.add(info1);
			
			createBagBean.setBatchInfos(BatchInfos);	
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			couponbatch couponbatch=new couponbatchWapper().getCouponBatchByBagCode(createBagCall.getbagCode()).get(0);
			new couponbatchWapper().setIsInvalid(couponbatch.getBatchCode());
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode(createBagCall.getbagCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		
			
			verifyReturn(4);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_025() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-套券批次有两个批次");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
			BatchInfo info=new BatchInfo();
			info.setCouponName("自动化创建套券优惠券名称-子套券");
			info.setCouponDes("自动化创建套券优惠券描述-子套券");
			info.setApplyMemo("自动化创建申请理由-子套券");
			info.setOrderMinAmount(new BigDecimal(2));
			info.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds = new ArrayList<String>();
			info.setProductIds(productIds);
			List<Integer> SellerIds = new ArrayList<Integer>();
			info.setSellerIds(SellerIds);
			List<Integer> ActivityIds = new ArrayList<Integer>();
			info.setActivityIds(ActivityIds);
			List<Integer> Brands = new ArrayList<Integer>();
			info.setBrands(Brands);
			List<Integer> Countrys = new ArrayList<Integer>();
			info.setCountrys(Countrys);
			List<Integer> Categories = new ArrayList<Integer>();
			info.setCategories(Categories);
			info.setLimitPspProduct(false);
			BatchInfos.add(info);
			
			BatchInfo info1=new BatchInfo();
			info1.setCouponName("自动化创建套券优惠券名称-子套券1");
			info1.setCouponDes("自动化创建套券优惠券描述-子套券1");
			info1.setApplyMemo("自动化创建申请理由-子套券1");
			info1.setOrderMinAmount(new BigDecimal(2));
			info1.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds1 = new ArrayList<String>();
			info1.setProductIds(productIds1);
			List<Integer> SellerIds1 = new ArrayList<Integer>();
			info1.setSellerIds(SellerIds1);
			List<Integer> ActivityIds1 = new ArrayList<Integer>();
			info1.setActivityIds(ActivityIds1);
			List<Integer> Brands1 = new ArrayList<Integer>();
			info1.setBrands(Brands1);
			List<Integer> Countrys1 = new ArrayList<Integer>();
			info1.setCountrys(Countrys1);
			List<Integer> Categories1 = new ArrayList<Integer>();
			info1.setCategories(Categories1);
			info1.setLimitPspProduct(false);
			BatchInfos.add(info1);
			
			createBagBean.setBatchInfos(BatchInfos);	
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);

			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode(createBagCall.getbagCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		
			
			verifyReturn(4);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_014() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-套券批次中都是无效子任务");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(111);
			couponbatch couponbatch=new couponbatchWapper().getCouponBatchByBagCode(createBagCall.getbagCode()).get(0);
			new couponbatchWapper().setIsInvalid(couponbatch.getBatchCode());
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode(createBagCall.getbagCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();		

			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("套券中没有有效的子批次"), "验证errorMessage");
			Logger.verifyEquals(2, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("套券中没有有效的子批次"), "验证message");				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	@Ignore
	public void Ts_createTaskByUserId_015() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证batchCode-套券批次中没有子任务(这种情况不存在，套券不会创建成功)");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_016() {
		Logger.start(true,"根据用户Id列表创建发券任务-notify=false-不通知用户");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			verifyReturn(1);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_017() {
		Logger.start(true,"根据用户Id列表创建发券任务-notify=true-通知用户");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(true);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			verifyReturn(1);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_018() {
		Logger.start(true,"根据用户Id列表创建发券任务-userIds为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(true);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("发放用户数必须在1-1000之间"), "验证errorMessage");
			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("发放用户数必须在1-1000之间"), "验证message");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_019() {
		Logger.start(true,"根据用户Id列表创建发券任务-batchType为空时自动识别类型-普通批次");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			createtaskbyuseridBean.setUserIds(userIds);
			//createtaskbyuseridBean.setBatchType(0);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(true);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();
			verifyReturn(1);
//			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("批次类型必须是1或2，1：普通批次，2：套券"), "验证errorMessage");
//			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
//			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("批次类型必须是1或2，1：普通批次，2：套券"), "验证message");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_032() {
		Logger.start(true,"根据用户Id列表创建发券任务-batchType为空时自动识别类型-套券");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setTotalNum(3000);
			List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
			BatchInfo info=new BatchInfo();
			info.setCouponName("自动化创建套券优惠券名称-子套券");
			info.setCouponDes("自动化创建套券优惠券描述-子套券");
			info.setApplyMemo("自动化创建申请理由-子套券");
			info.setOrderMinAmount(new BigDecimal(2));
			info.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds = new ArrayList<String>();
			info.setProductIds(productIds);
			List<Integer> SellerIds = new ArrayList<Integer>();
			info.setSellerIds(SellerIds);
			List<Integer> ActivityIds = new ArrayList<Integer>();
			info.setActivityIds(ActivityIds);
			List<Integer> Brands = new ArrayList<Integer>();
			info.setBrands(Brands);
			List<Integer> Countrys = new ArrayList<Integer>();
			info.setCountrys(Countrys);
			List<Integer> Categories = new ArrayList<Integer>();
			info.setCategories(Categories);
			info.setLimitPspProduct(false);
			BatchInfos.add(info);
			
			createBagBean.setBatchInfos(BatchInfos);	
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);

			createtaskbyuseridBean.setUserIds(userIds);
			//createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode(createBagCall.getbagCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			
			Logger.verifyEquals("null", createtaskbyuseridCall.getErrorMessage(), "验证errorMessage");
			Logger.verifyEquals(0, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals("操作成功！", createtaskbyuseridCall.getMessage(), "验证message");
			//couponsendtask
			couponsendtask couponsendtask=new couponsendtaskWapper().selectByCouponBatchCode(createtaskbyuseridBean.getBatchCode()).get(0);
			Logger.verifyEquals(couponsendtask.getTaskId(), createtaskbyuseridCall.getTaskId(), "验证数据库couponsendtask表中的TaskId与返回的TaskId是否一致");
			Logger.verifyEquals(createtaskbyuseridBean.getUserIds().size(), couponsendtask.getTotalNum(), "验证数据库couponsendtask表中的TotalNum");
			Logger.verifyEquals(createtaskbyuseridBean.getUserIds().size(), couponsendtask.getSuccessNum(), "验证数据库couponsendtask表中的SuccessNum");
			Logger.verifyEquals(0, couponsendtask.getFailNum(), "验证数据库couponsendtask表中的FailNum");
			Logger.verifyEquals(2, couponsendtask.getStatus(), "验证数据库couponsendtask表中的Status");
			Logger.verifyEquals(4, couponsendtask.getTaskType(), "验证数据库couponsendtask表中的TaskType");
			Logger.verifyEquals(createtaskbyuseridBean.getNotify(), couponsendtask.getIsNotify(), "验证数据库couponsendtask表中的Notify");
			//验证couponsendsubtask
			List<couponsendsubtask> couponsendsubtask=new couponsendsubtaskWapper().selectcouponsendsubtaskByTaskId(couponsendtask.getTaskId());
			int subTaskQuantity=0;
			int subTaskPerUser=100/createBagBean.getBatchInfos().size(); //每个子任务发放用户数量 = 每次发放券数 / 批次数
		    if (createtaskbyuseridBean.getUserIds().size() % subTaskPerUser == 0) {
		    	subTaskQuantity= createtaskbyuseridBean.getUserIds().size() / subTaskPerUser;
			  } else {
				  subTaskQuantity= createtaskbyuseridBean.getUserIds().size() / subTaskPerUser + 1;
			  }
		    for (int i = 0; i < subTaskQuantity; i++) {
			     int count=i+1;
			     int TotalNumPersubTask=calcGenerateQuantity(subTaskQuantity,count,subTaskPerUser,createtaskbyuseridBean.getUserIds().size());//每个Task的userId数量
			     Logger.verifyEquals(SubBagString(createtaskbyuseridBean.getUserIds(),TotalNumPersubTask,i,subTaskPerUser),couponsendsubtask.get(i).getUserIds() , "验证数据库couponsendsubtask表第"+count+"个子任务中的UserIds字段");
			     Logger.verifyEquals(TotalNumPersubTask,couponsendsubtask.get(i).getTotalNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的TotalNum字段");
			     Logger.verifyEquals(TotalNumPersubTask,couponsendsubtask.get(i).getSuccessNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的SuccessNum字段");
			     Logger.verifyEquals(0,couponsendsubtask.get(i).getFailNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的FailNum字段");
		    }
			Logger.verifyEquals(subTaskQuantity, couponsendsubtask.size(), "验证TaskId="+couponsendtask.getTaskId()+" 的子任务couponsendsubtask数量");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_021() {
		Logger.start(true,"根据用户Id列表创建发券任务-createrName为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("");
			createtaskbyuseridBean.setNotify(true);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("必须传入创建者姓名"), "验证errorMessage");
			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("必须传入创建者姓名"), "验证message");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Ts_createTaskByUserId_022() {
		Logger.start(true,"根据用户Id列表创建发券任务-notify为空");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			//createtaskbyuseridBean.setNotify(true);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			
			verifyReturn(1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_createTaskByUserId_024() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证一个套券有21个批次");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setTotalNum(3000);
			List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
			BatchInfo info=new BatchInfo();
			info.setCouponName("自动化创建套券优惠券名称-子套券");
			info.setCouponDes("自动化创建套券优惠券描述-子套券");
			info.setApplyMemo("自动化创建申请理由-子套券");
			info.setOrderMinAmount(new BigDecimal(2));
			info.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds = new ArrayList<String>();
			info.setProductIds(productIds);
			List<Integer> SellerIds = new ArrayList<Integer>();
			info.setSellerIds(SellerIds);
			List<Integer> ActivityIds = new ArrayList<Integer>();
			info.setActivityIds(ActivityIds);
			List<Integer> Brands = new ArrayList<Integer>();
			info.setBrands(Brands);
			List<Integer> Countrys = new ArrayList<Integer>();
			info.setCountrys(Countrys);
			List<Integer> Categories = new ArrayList<Integer>();
			info.setCategories(Categories);
			info.setLimitPspProduct(false);
			for(int i=0;i<20;i++)
			{
			 BatchInfos.add(info);
			}
			createBagBean.setBatchInfos(BatchInfos);	
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			List<Integer> userIds=new ArrayList<Integer>();
			for(int i=1;i<10;i++)
			{
			  userIds.add(i);
			}
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode(createBagCall.getbagCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			
			Logger.verifyEquals("null", createtaskbyuseridCall.getErrorMessage(), "验证errorMessage");
			Logger.verifyEquals(0, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals("操作成功！", createtaskbyuseridCall.getMessage(), "验证message");
			//couponsendtask
			couponsendtask couponsendtask=new couponsendtaskWapper().selectByCouponBatchCode(createtaskbyuseridBean.getBatchCode()).get(0);
			Logger.verifyEquals(couponsendtask.getTaskId(), createtaskbyuseridCall.getTaskId(), "验证数据库couponsendtask表中的TaskId与返回的TaskId是否一致");
			Logger.verifyEquals(createtaskbyuseridBean.getUserIds().size(), couponsendtask.getTotalNum(), "验证数据库couponsendtask表中的TotalNum");
			Logger.verifyEquals(createtaskbyuseridBean.getUserIds().size(), couponsendtask.getSuccessNum(), "验证数据库couponsendtask表中的SuccessNum");
			Logger.verifyEquals(0, couponsendtask.getFailNum(), "验证数据库couponsendtask表中的FailNum");
			Logger.verifyEquals(2, couponsendtask.getStatus(), "验证数据库couponsendtask表中的Status");
			Logger.verifyEquals(4, couponsendtask.getTaskType(), "验证数据库couponsendtask表中的TaskType");
			Logger.verifyEquals(createtaskbyuseridBean.getNotify(), couponsendtask.getIsNotify(), "验证数据库couponsendtask表中的Notify");
			//验证couponsendsubtask
			List<couponsendsubtask> couponsendsubtask=new couponsendsubtaskWapper().selectcouponsendsubtaskByTaskId(couponsendtask.getTaskId());
			int subTaskQuantity=0;
			int subTaskPerUser=100/createBagBean.getBatchInfos().size(); //每个子任务发放用户数量 = 每次发放券数 / 批次数
		    if (createtaskbyuseridBean.getUserIds().size() % subTaskPerUser == 0) {
		    	subTaskQuantity= createtaskbyuseridBean.getUserIds().size() / subTaskPerUser;
			  } else {
				  subTaskQuantity= createtaskbyuseridBean.getUserIds().size() / subTaskPerUser + 1;
			  }
		    for (int i = 0; i < subTaskQuantity; i++) {
			     int count=i+1;
			     int TotalNumPersubTask=calcGenerateQuantity(subTaskQuantity,count,subTaskPerUser,createtaskbyuseridBean.getUserIds().size());//每个Task的userId数量
			     Logger.verifyEquals(SubBagString(createtaskbyuseridBean.getUserIds(),TotalNumPersubTask,i,subTaskPerUser),couponsendsubtask.get(i).getUserIds() , "验证数据库couponsendsubtask表第"+count+"个子任务中的UserIds字段");
			     Logger.verifyEquals(TotalNumPersubTask,couponsendsubtask.get(i).getTotalNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的TotalNum字段");
			     Logger.verifyEquals(TotalNumPersubTask,couponsendsubtask.get(i).getSuccessNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的SuccessNum字段");
			     Logger.verifyEquals(0,couponsendsubtask.get(i).getFailNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的FailNum字段");
		    }
			Logger.verifyEquals(subTaskQuantity, couponsendsubtask.size(), "验证TaskId="+couponsendtask.getTaskId()+" 的子任务couponsendsubtask数量");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_createTaskByUserId_030() {
		Logger.start(true,"根据用户Id列表创建发券任务-验证套券发放用户超过1000");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setTotalNum(3000);
			List<BatchInfo> BatchInfos=new ArrayList<BatchInfo>();
			BatchInfo info=new BatchInfo();
			info.setCouponName("自动化创建套券优惠券名称-子套券");
			info.setCouponDes("自动化创建套券优惠券描述-子套券");
			info.setApplyMemo("自动化创建申请理由-子套券");
			info.setOrderMinAmount(new BigDecimal(2));
			info.setDeductionMaxAmount(new BigDecimal(1));
			List<String> productIds = new ArrayList<String>();
			info.setProductIds(productIds);
			List<Integer> SellerIds = new ArrayList<Integer>();
			info.setSellerIds(SellerIds);
			List<Integer> ActivityIds = new ArrayList<Integer>();
			info.setActivityIds(ActivityIds);
			List<Integer> Brands = new ArrayList<Integer>();
			info.setBrands(Brands);
			List<Integer> Countrys = new ArrayList<Integer>();
			info.setCountrys(Countrys);
			List<Integer> Categories = new ArrayList<Integer>();
			info.setCategories(Categories);
			info.setLimitPspProduct(false);
			for(int i=0;i<100;i++)
			{
			 BatchInfos.add(info);
			}
			createBagBean.setBatchInfos(BatchInfos);	
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			List<Integer> userIds=new ArrayList<Integer>();
			for(int i=1;i<1002;i++)
			{
			  userIds.add(i);
			}
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(2);//1：普通批次，2：套券
			createtaskbyuseridBean.setBatchCode(createBagCall.getbagCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();	
			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("userIds:发放用户数必须在1-1000之间"), "验证errorMessage");
			Logger.verifyEquals(1, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("userIds:发放用户数必须在1-1000之间"), "验证message");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_createTaskByUserId_033() {
		Logger.start(true,"根据用户Id列表创建发券任务-商家券-分销");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			SellerCreateBatchBean createCouponBean = couponCallService.setDefaultSellerCreateBatchBean();
			SellerCreateBatchCall createCouponCall = couponCallService.SellerCreateBatch(createCouponBean);
			
	        //分销
			couponbatchWapper couponbatchWapper=new couponbatchWapper();
			couponbatchWapper.setPlatformSource(1, createCouponCall.getBatchCode());
			
			List<Integer> userIds=new ArrayList<Integer>();
			userIds.add(11);
			createtaskbyuseridBean.setUserIds(userIds);
			createtaskbyuseridBean.setBatchType(1);
			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
			createtaskbyuseridBean.setCreaterId(22);
			createtaskbyuseridBean.setCreaterName("autoTest");
			createtaskbyuseridBean.setNotify(false);
			createtaskbyuseridCall.setData(createtaskbyuseridBean);
			createtaskbyuseridCall.callService();
		//	createtaskbyuseridCall.callService();

			Logger.verifyEquals(true, createtaskbyuseridCall.getErrorMessage().contains("不属于平台批次"), "验证errorMessage");
			Logger.verifyEquals(2, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
			Logger.verifyEquals(true, createtaskbyuseridCall.getMessage().contains("不属于平台批次"), "验证message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	@Test
//	@Category({P3.class})
//	@TestCase
//	public void Ts_createTaskByUserId_026() {
//		Logger.start(true,"根据用户Id列表创建发券任务-随机兑换码-");
//		try {
//			//生成批次及兑换码 
//			CouponServiceMCallServiceV2 couponMCallService = new CouponServiceMCallServiceV2();
//			CreateCouponBean createCouponBean = couponMCallService.setDefaultPlatformCreateCouponBeanForConversion();
//
//			CreateCouponCall createCouponCall = couponMCallService.createPlatformCoupon(createCouponBean);
//
//			List<String> batchCodes = new ArrayList<>();
//			batchCodes.add(createCouponCall.getBatchCode());
//
//			CreateBean createBean = couponMCallService.setDefaultRandomCreateBean(batchCodes);
//			CreateCall createCall = couponMCallService.create(createBean);
//
//			
//			List<Integer> userIds=new ArrayList<Integer>();
//			userIds.add(11);
//			createtaskbyuseridBean.setUserIds(userIds);
//			createtaskbyuseridBean.setBatchType(1);//1：普通批次，2：套券
//			createtaskbyuseridBean.setBatchCode(createCouponCall.getBatchCode());
//			createtaskbyuseridBean.setCreaterId(22);
//			createtaskbyuseridBean.setCreaterName("autoTest");
//			createtaskbyuseridBean.setNotify(false);
//			createtaskbyuseridCall.setData(createtaskbyuseridBean);
//			createtaskbyuseridCall.callService();	
//			
//			
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
	
	private void verifyReturn(Integer taskType)
	{
		Logger.verifyEquals("null", createtaskbyuseridCall.getErrorMessage(), "验证errorMessage");
		Logger.verifyEquals(0, createtaskbyuseridCall.getErrorCode1(), "验证errorcode");
		Logger.verifyEquals("操作成功！", createtaskbyuseridCall.getMessage(), "验证message");
		int taskId=checkcouponsendtask(taskType);
		couponsendsubtask(taskId);
		
	}
	private int checkcouponsendtask(Integer taskType)
	{
		couponsendtask couponsendtask=new couponsendtaskWapper().selectByCouponBatchCode(createtaskbyuseridBean.getBatchCode()).get(0);
		Logger.verifyEquals(couponsendtask.getTaskId(), createtaskbyuseridCall.getTaskId(), "验证数据库couponsendtask表中的TaskId与返回的TaskId是否一致");
		Logger.verifyEquals(createtaskbyuseridBean.getUserIds().size(), couponsendtask.getTotalNum(), "验证数据库couponsendtask表中的TotalNum");
		Logger.verifyEquals(createtaskbyuseridBean.getUserIds().size(), couponsendtask.getSuccessNum(), "验证数据库couponsendtask表中的SuccessNum");
		Logger.verifyEquals(0, couponsendtask.getFailNum(), "验证数据库couponsendtask表中的FailNum");
		Logger.verifyEquals(2, couponsendtask.getStatus(), "验证数据库couponsendtask表中的Status");
		Logger.verifyEquals(taskType, couponsendtask.getTaskType(), "验证数据库couponsendtask表中的TaskType");
		Logger.verifyEquals(createtaskbyuseridBean.getNotify(), couponsendtask.getIsNotify(), "验证数据库couponsendtask表中的Notify");
		return couponsendtask.getTaskId();
	}
	private void couponsendsubtask(Integer taskId)
	{
		List<couponsendsubtask> couponsendsubtask=new couponsendsubtaskWapper().selectcouponsendsubtaskByTaskId(taskId);
		int subTaskQuantity=0;// 子任务个数   //每个子任务发放用户数量 = 每次发放券数 / 批次数
	    if (createtaskbyuseridBean.getUserIds().size() % 100 == 0) {
	    	subTaskQuantity= createtaskbyuseridBean.getUserIds().size() / 100;
		  } else {
			  subTaskQuantity= createtaskbyuseridBean.getUserIds().size() / 100 + 1;
		  }
	    for (int i = 0; i < subTaskQuantity; i++) {
		     int count=i+1;
		     int TotalNumPersubTask=calcGenerateQuantity(subTaskQuantity,count,100,createtaskbyuseridBean.getUserIds().size());//每个Task的userId数量
		     Logger.verifyEquals(SubString(createtaskbyuseridBean.getUserIds(),TotalNumPersubTask,i),couponsendsubtask.get(i).getUserIds() , "验证数据库couponsendsubtask表第"+count+"个子任务中的UserIds字段");
		     Logger.verifyEquals(TotalNumPersubTask,couponsendsubtask.get(i).getTotalNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的TotalNum字段");
		     Logger.verifyEquals(TotalNumPersubTask,couponsendsubtask.get(i).getSuccessNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的SuccessNum字段");
		     Logger.verifyEquals(0,couponsendsubtask.get(i).getFailNum() , "验证数据库couponsendsubtask表第"+count+"个子任务中的FailNum字段");
	    }
		Logger.verifyEquals(subTaskQuantity, couponsendsubtask.size(), "验证TaskId="+taskId+" 的子任务couponsendsubtask数量");
	}
	/**
	 * 
	 * @param totalSubTaskQuantity 子任务个数
	 * @param currentSubTaskNum 当前第几个子任务
	 * @param generateQuantityPerSubTask 每个子任务做多可以发放多少个用户，目前是100
	 * @param totalGenerateQuantity 总用户数
	 * @return
	 */
    private int calcGenerateQuantity(int totalSubTaskQuantity, int currentSubTaskNum, int generateQuantityPerSubTask, int totalGenerateQuantity) {
        if (currentSubTaskNum < totalSubTaskQuantity) {
            return generateQuantityPerSubTask;
        } else {
            return totalGenerateQuantity - ((totalSubTaskQuantity - 1) * generateQuantityPerSubTask);
        }
    }
    /**
     * 用于普通优惠券
     * @param userIds
     * @param TotalNumPersubTask
     * @param currentSubTaskNum
     * @return
     */
    private String SubString(List<Integer> userIds,int TotalNumPersubTask,int currentSubTaskNum){
    	//return StringUtils.join(userIds.toArray(), ",") ;
    	String userIdStr="";
    	if(currentSubTaskNum==0 && TotalNumPersubTask<=100)
    	{
        	for(int i=0;i<TotalNumPersubTask;i++)
        	{
        		userIdStr+=userIds.get(i)+",";
        	}
    	}
    	else
    	{
    		int total=currentSubTaskNum*TotalNumPersubTask;
    		if(total<100)
    		{
	    		for(int i=(userIds.size()-total);i<userIds.size();i++)
	        	{
	        		userIdStr+=userIds.get(i)+",";
	        	}
    		}
    		else
    		{
    			for(int i=total;i<((currentSubTaskNum+1)*TotalNumPersubTask);i++)
	        	{
	        		userIdStr+=userIds.get(i)+",";
	        	}
    		}
    	}
    	return userIdStr.substring(0, userIdStr.length()-1);
    }
    
    /**
     * 用于套券
     * @param userIds
     * @param TotalNumPersubTask
     * @param currentSubTaskNum
     * @return
     */
    private String SubBagString(List<Integer> userIds,int TotalNumPersubTask,int currentSubTaskNum,int subTaskQuantity){
    	//return StringUtils.join(userIds.toArray(), ",") ;
    	String userIdStr="";
    	if(currentSubTaskNum==0 && TotalNumPersubTask<=subTaskQuantity)
    	{
        	for(int i=0;i<TotalNumPersubTask;i++)
        	{
        		userIdStr+=userIds.get(i)+",";
        	}
    	}
    	else
    	{
//    		int total=currentSubTaskNum*TotalNumPersubTask;
//    		for(int i=(userIds.size()-total);i<userIds.size();i++)
//        	{
//        		userIdStr+=userIds.get(i)+",";
//        	}
    		int total=currentSubTaskNum*TotalNumPersubTask;
    		if(total<subTaskQuantity)
    		{
	    		for(int i=(userIds.size()-total);i<userIds.size();i++)
	        	{
	        		userIdStr+=userIds.get(i)+",";
	        	}
    		}
    		else
    		{
    			for(int i=total;i<((currentSubTaskNum+1)*TotalNumPersubTask);i++)
	        	{
	        		userIdStr+=userIds.get(i)+",";
	        	}
    		}
    	}
    	return userIdStr.substring(0, userIdStr.length()-1);
    }
}